package frontend.core;

import org.apache.wicket.Page;
import org.apache.wicket.authroles.authentication.AbstractAuthenticatedWebSession;
import org.apache.wicket.authroles.authentication.AuthenticatedWebApplication;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.apache.wicket.util.file.Folder;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import frontend.pages.HomePage;
import frontend.pages.base.LoginPage;

public class PrometeicaWebApplication extends AuthenticatedWebApplication implements ApplicationContextAware {

	private static ApplicationContext context;

	@Override
	public Class<? extends Page> getHomePage() {
		return HomePage.class;
	}

	@Override
	protected void init() {
		super.init();
		getDebugSettings().setDevelopmentUtilitiesEnabled(true);
		addSpringInitializer();
	}	
	
	protected void addSpringInitializer() {
		getComponentInstantiationListeners().add(new SpringComponentInjector(this));
	}

	@Override
	protected Class<? extends WebPage> getSignInPageClass() {
		return LoginPage.class;
	}

	@Override
	protected Class<? extends AbstractAuthenticatedWebSession> getWebSessionClass() {
		return PrometeicaWebSession.class;
	}

	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		context = applicationContext;
	}

	public static <T> T getService(Class<T> serviceClazz) {
		return context.getBean(serviceClazz);
	}

}
